package com.s3.khospitalds.controller;

import com.s3.khospitalds.common.R;
import com.s3.khospitalds.common.ResponseEntity;
import com.s3.khospitalds.entity.DoctorResignInfo;
import com.s3.khospitalds.entity.Hasnurse;
import com.s3.khospitalds.service.HasnurseService;
import com.s3.khospitalds.service.impl.HasnurseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: xw
 * @CreateTime: 2025/2/20
 * @Description: 护士
 * @Version: 1.0
 */
@RestController
@CrossOrigin(origins = "*")
public class HasnurseController {
    @Autowired
    private HasnurseServiceImpl hasnurseService;
    @GetMapping("/Nurse")
    public R getAllNurse() {
        return new R().addData("list1",hasnurseService.getAllHasnurse());
    }
    @GetMapping("/getAllNurse")
    public ResponseEntity getHasnurseService(Integer pageNum, Integer pageSize, String search){//查询所有的护士方法
            pageNum = pageNum == null ? 1 : pageNum;
            pageSize = pageSize == null ? 10 : pageSize;
            search = search == null ? "" : search;
            return hasnurseService.getHasnurseService(pageNum,pageSize,search);
    }

    @GetMapping("/getResignNurse")
    public ResponseEntity getResignNurse(){//查询所有已经离职的护士
        return hasnurseService.getResignHasnurse();
    }

    @GetMapping("/getNurse")
    public R getHasnurse(@RequestBody String name,String department) {//条件查询根据姓名或科室
        List<Hasnurse> byDepartmentAndName = hasnurseService.findByDepartmentAndName(department, name);
        return new R().addData("Nurse",byDepartmentAndName);
    }
    @PostMapping("/insertNurse")
    public R insertNurse(@RequestBody Hasnurse hasnurse) {//新增护士
        return new R().addData("add",hasnurseService.insertHasnurse(hasnurse));
    }
    @PostMapping("/updateNurse")
    public R UpdateNurse(@RequestBody Hasnurse hasnurse) {//修改护士
        return new R().addData("update",hasnurseService.updateHasnurse(hasnurse));
    }
    @PostMapping("/deleteNurse")
    public R deleteNurseById(@RequestBody DoctorResignInfo doctorResignInfo) {//根据id删除护士
        return new R().addData("delete",hasnurseService.deleteHasnurse(doctorResignInfo));
    }
}
